
if class == nil then require 'class' end
require 'card'

if Deck == nil then Deck = class({}) end


function Deck:constructor(o)
    self.deck = {}
    for i = 2, 14 do
        for j = 1, 4 do
            local card = Card(i,j,o)
            table.insert(self.deck, card )
        end
    end
end

function Deck:Add( card )
    table.insert( self.deck, card )
end

function Deck:Shuffle()
    for k, v in pairs( self.deck ) do
        local i = RandomInt(1, TableCount(self.deck) )
        self.deck[i],self.deck[k] = self.deck[k],self.deck[i]
    end
end

function Deck:CardsLeft()
    return TableCount( self.deck )
end


function Deck:ToString()
    local output = ""
    for _, v in pairs( self.deck ) do
        output = output .. v:ToString() .. " "
    end
    return output
end
function Deck:Deal(faceUp)
    local rand = RandomInt(1, TableCount(self.deck))
    local dealCard = table.remove(self.deck,rand)
    dealCard.faceUp = faceUp
    return dealCard
end

function Deck:Remove(o)
    if type(o) == "number" then
        table.remove(self.deck, o)
    end
    if type(o) == "table" then
        local k = TableFindKey( self.deck, o )
        table.remove(self.deck, k)
    end
end

function Deck:ToArray()
    return self.deck
end

function Deck:ToList()
    return self.deck
end
